package com.zfc.life.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zfc.life.domain.Beautiful;
import com.zfc.life.mapper.BeautifulMapper;
import com.zfc.life.service.BeautifulService;
import com.zfc.life.utils.file.FileUploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author zfc
 * @Date 2024/8/15 11:25
 * @Description BeautifulServiceImpl
 */
@Service
public class BeautifulServiceImpl implements BeautifulService {

    @Autowired
    private BeautifulMapper beautifulMapper;

    @Override
    public PageInfo listBeautiful(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Beautiful> list = beautifulMapper.listBeautiful();
        PageInfo info = new PageInfo(list);
        return info;
    }

    @Override
    public List<Beautiful> listBeautiful() {
        return beautifulMapper.listBeautiful();
    }

    @Override
    public Integer addBeautiful(Beautiful beautiful) {
        return beautifulMapper.addBeautiful(beautiful);
    }

    @Override
    public Integer deleteBeautiful(Long id) {
        Beautiful beautiful = beautifulMapper.queryBeautifulById(id);
        if (!StringUtils.isEmpty(beautiful)){
            //删除图片
            FileUploadUtils.deleteFile(beautiful.getImagePath());
            return beautifulMapper.deleteBeautiful(id);
        }

        return 0;
    }

    @Override
    public Integer modifyBeautiful(Beautiful beautiful) {
        return beautifulMapper.modifyBeautiful(beautiful);
    }
}
